package com.wechat.back.controller;

import com.wechat.back.anno.OptLog;
import com.wechat.back.pojo.comment.ArticleLike;
import com.wechat.back.pojo.comment.PoiLike;
import com.wechat.back.pojo.tools.Result;
import com.wechat.back.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/like")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @OptLog(optModule = "点赞模块",optType = "添加", optDesc = "添加文章点赞")
    @PostMapping("/addArticleLike")
    public Result addArticleLike(@RequestBody @Validated(ArticleLike.Add.class) ArticleLike articleLike){
        likeService.addArticleLike(articleLike);
        return Result.success();
    }

    @OptLog(optModule = "点赞模块",optType = "添加", optDesc = "添加poi点赞")
    @PostMapping("/addPoiLike")
    public Result addPoiLike(@RequestBody @Validated(ArticleLike.Add.class) PoiLike poiLike){
        likeService.addPoiLike(poiLike);
        return Result.success();
    }

    @GetMapping("/listArticleLike")
    public Result<List<ArticleLike>> listArticleLike(){
        List<ArticleLike> listArticleLike = likeService.listArticleLike(new ArticleLike());
        return Result.success(listArticleLike);
    }

    @GetMapping("/listPoiLike")
    public Result<List<PoiLike>> listPoiLike(
            @RequestParam(required = false) Integer poiId
    ){
        List<PoiLike> listPoiLike = likeService.listPoiLike(poiId);
        return Result.success(listPoiLike);
    }

    @OptLog(optModule = "点赞模块",optType = "删除", optDesc = "删除文章点赞")
    @DeleteMapping("/deleteArticleLike")
    public Result deleteArticleLike(Integer likeId){
        likeService.deleteArticleLike(likeId);
        return Result.success();
    }

    @OptLog(optModule = "点赞模块",optType = "删除", optDesc = "删除poi点赞")
    @DeleteMapping("/deletePoiLike")
    public Result deletePoiLike(Integer likeId){
        likeService.deletePoiLike(likeId);
        return Result.success();
    }
}
